package com.it.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.it.entity.worker.SystemUser;
import com.it.mapper.SystemUserMapper;
import com.it.service.LoginService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.R;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Override
    public R checkLogin(SystemUser systemUser) {
        LambdaQueryWrapper<SystemUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SystemUser::getUsername,systemUser.getUsername());
        SystemUser user = systemUserMapper.selectOne(wrapper);
        if(ObjectUtils.isEmpty(user)){
            return R.Failed("没有此用户");
        }
        if(!user.getPassword().equals(systemUser.getPassword())){
            return R.Failed("密码错误");
        }
        //脱敏
        user.setPassword("****");
        return R.Success("登录成功",user);
    }
}
